function navigateTo(url) {
	uni.navigateTo({
		url,
	})
}

function reLaunch(url) {
	uni.reLaunch({
		url
	})
}

function redirectTo(url) {
	uni.redirectTo({
		url
	});
}

function switchTab(url) {
	uni.switchTab({
		url
	})
}

function failToast(title, image) {
	uni.showToast({
		title: title ? title : "错误",
		icon: 'none',
		duration: 4000
	})
}

function successToast(title, ) {
	uni.showToast({
		title: title ? title : "成功",
		icon: 'success',
		duration: 2000
	})
}

function toast(title, ) {
	uni.showToast({
		title: title ? title : "",
		icon: 'none',
		duration: 2000
	})
}

function formatDate(date, type) {
	var date = new Date(date);
	var YY = date.getFullYear();
	var MM = date.getMonth() + 1;
	var DD = date.getDate();
	var hh = date.getHours();
	var mm = date.getMinutes();
	var ss = date.getSeconds();
	switch (type) {
		case "YY-MM-DD hh:mm:ss": {
			return [YY, MM, DD].map(formatNumber).join('-') + ' ' + [hh, mm, ss].map(formatNumber).join(':');
			break;

		};
	default: {
		return [YY, MM, DD].map(formatNumber).join('/') + ' ' + [hh, mm, ss].map(formatNumber).join(':');
		break;
	}
	}
	// return YY + MM + DD + " " + hh + mm + ss;
}
const formatNumber = n => {
	n = n.toString()
	return n[1] ? n : '0' + n
}

function guuid() {
	return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
		var r = Math.random() * 16 | 0,
			v = c == 'x' ? r : (r & 0x3 | 0x8);
		return v.toString(16);
	});
};


module.exports = {
	navigateTo, // 跳转至下一页面
	reLaunch, // 关闭所有页面，并跳转
	redirectTo, // 关闭当前页面，并跳转
	switchTab,
	successToast,
	failToast,
	toast,
	formatDate,
	guuid,
}
